document.querySelector('#btn-register').addEventListener('click',async () => {
    // 注册逻辑
    axios({
    method: 'post',
    url: '/register',
    data: {
        username: 'rose',
        password: '123456'
    }
})
//收集数据
const form = document.querySelector('.register-form');
const data = serialize(form, { hash: true , empty: true});
console.log('data:',data);

const { username, password } = data;
//非空验证
if (username === '' || password === '') {
    showToast('用户名或密码不能为空');
    return;
}
//长度校验
if (username.length < 3 || username.length > 10 || password.length < 3 || password.length > 10) {
    showToast('用户名密码长度必须在3到10之间');
    return;
}

//发送请求
// try{
    const res = await axios.post('/register', {
        username,
        password
    });
    showToast(res.message);
    //去登录
    setTimeout(() => {
        window.location.href = '/login.html';
    },1500)
// }catch(error){
//     showToast(error.response.data.message);
// }
})
